# @Time:2021/6/10 14:51
# @Author:5120195554王欣霏
# -*- coding = utf-8 -*-

import pygame


def blit_text(surface, text, pos, font, color=pygame.Color(255, 255, 255)):
    '''
    这个函数的作用是把文字绘制到窗体上
    :param surface: 窗口
    :param text:文本
    :param pos:位置
    :param font:字体
    :param color:颜色
    :return:
    '''
    words = [word.split(' ') for word in text.splitlines()]  # 以空格符为分割 取文本的内容
    # print(words)
    space = font.size(' ')[0]
    # print(space)
    max_width, max_height = surface.get_size()
    x = pos[0] + 10
    y = pos[1]
    for line in words:
        for word in line:
            word_surface = font.render(word, 0, color)
            word_width, word_height = word_surface.get_size()
            if x + word_width >= max_width:
                x = pos[0] + 10
                y += word_height
            surface.blit(word_surface, (x, y))
            x += word_width + space
        x = pos[0] + 10
        y += word_height + 2
